package com.hhf.feicodebackend.core.parser;

import com.hhf.feicodebackend.ai.model.enums.CodeGenTypeEnum;
import com.hhf.feicodebackend.common.ErrorCode;
import com.hhf.feicodebackend.core.parser.strategy.HtmlCodeParser;
import com.hhf.feicodebackend.core.parser.strategy.MultiFileCodeParser;
import com.hhf.feicodebackend.exception.BusinessException;

/**
 * @Author hhf
 * @Date 2025/8/11
 * @Description 代码解释执行器
 * 根据代码类型执行相应的解释逻辑
 */
public class CodeParserExecutor {
    private static final HtmlCodeParser htmlCodeParser = new HtmlCodeParser();
    private static final MultiFileCodeParser multiFileCodeParser = new MultiFileCodeParser();

    /**
     * 执行代码解析
     * @param codeContent 代码内容
     * @param codeGenTypeEnum 生成代码类型
     * @return
     */
    public static Object execute(String codeContent, CodeGenTypeEnum codeGenTypeEnum){
        return switch (codeGenTypeEnum) {
            case HTML -> htmlCodeParser.parseCode(codeContent);
            case MULTI_FILE -> multiFileCodeParser.parseCode(codeContent);
            default -> {
                String errorMessage = "不支持生成类型:" + codeGenTypeEnum.getValue();
                throw new BusinessException(ErrorCode.SYSTEM_ERROR, errorMessage);
            }
        };
    }
}
